/*
 * A view that presents the user with one question at a time from a questionlist (a generated test).
 * Once the user reached the last question he/she can get to the resultview to see how he/she did.
 */

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TestView.java
 *
 * Created on 2011-maj-11, 11:24:27
 */
package edu.chalmers.se.tda367.gui.view;

import edu.chalmers.se.tda367.main.Pluggis;
import edu.chalmers.se.tda367.observer.GlobalObserverList;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import edu.chalmers.se.tda367.model.Test;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JOptionPane;

/**
 *
 * @author bgrn
 */
public class TestView extends javax.swing.JPanel implements PropertyChangeListener {

    GlobalObserverList observers = GlobalObserverList.getInstance();
    private Test test;
    private int svar = 0;

    public void propertyChange(PropertyChangeEvent pce) {
        String name = pce.getPropertyName();
        System.out.println(name);

    }

    /** Creates new form TestView */
    public TestView() {
        initComponents();


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pluggisRuggis = new javax.swing.JLabel();
        questionLabel = new javax.swing.JLabel();
        previousButton = new javax.swing.JButton();
        nextButton = new javax.swing.JButton();
        answerField = new javax.swing.JTextField();
        questionNumber = new javax.swing.JLabel();
        userImageButton = new javax.swing.JButton();
        questionButton5 = new javax.swing.JButton();
        questionButton6 = new javax.swing.JButton();
        questionButton7 = new javax.swing.JButton();
        questionButton3 = new javax.swing.JButton();
        questionButton4 = new javax.swing.JButton();
        questionButton8 = new javax.swing.JButton();
        questionButton9 = new javax.swing.JButton();
        questionButton11 = new javax.swing.JButton();
        questionButton2 = new javax.swing.JButton();
        questionButton10 = new javax.swing.JButton();
        questionButton14 = new javax.swing.JButton();
        questionButton13 = new javax.swing.JButton();
        questionButton12 = new javax.swing.JButton();
        questionButton15 = new javax.swing.JButton();
        questionButton20 = new javax.swing.JButton();
        questionButton19 = new javax.swing.JButton();
        questionButton18 = new javax.swing.JButton();
        questionButton17 = new javax.swing.JButton();
        questionButton16 = new javax.swing.JButton();
        questionButton1 = new javax.swing.JButton();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(edu.chalmers.se.tda367.main.Main.class).getContext().getResourceMap(TestView.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setMaximumSize(new java.awt.Dimension(820, 550));
        setMinimumSize(new java.awt.Dimension(820, 550));
        setName("Form"); // NOI18N

        pluggisRuggis.setIcon(resourceMap.getIcon("pluggisRuggis.icon")); // NOI18N
        pluggisRuggis.setText(resourceMap.getString("pluggisRuggis.text")); // NOI18N
        pluggisRuggis.setName("pluggisRuggis"); // NOI18N

        questionLabel.setFont(resourceMap.getFont("questionLabel.font")); // NOI18N
        questionLabel.setText(resourceMap.getString("questionLabel.text")); // NOI18N
        questionLabel.setName("questionLabel"); // NOI18N

        previousButton.setFont(resourceMap.getFont("previousButton.font")); // NOI18N
        previousButton.setText(resourceMap.getString("previousButton.text")); // NOI18N
        previousButton.setName("previousButton"); // NOI18N
        previousButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                previousButtonActionPerformed(evt);
            }
        });

        nextButton.setFont(resourceMap.getFont("nextButton.font")); // NOI18N
        nextButton.setText(resourceMap.getString("nextButton.text")); // NOI18N
        nextButton.setName("nextButton"); // NOI18N
        nextButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nextButtonActionPerformed(evt);
            }
        });

        answerField.setFont(resourceMap.getFont("answerField.font")); // NOI18N
        answerField.setName("answerField"); // NOI18N

        questionNumber.setFont(resourceMap.getFont("questionNumber.font")); // NOI18N
        questionNumber.setText(resourceMap.getString("questionNumber.text")); // NOI18N
        questionNumber.setName("questionNumber"); // NOI18N

        userImageButton.setText(resourceMap.getString("userImageButton.text")); // NOI18N
        userImageButton.setMaximumSize(new java.awt.Dimension(109, 126));
        userImageButton.setMinimumSize(new java.awt.Dimension(109, 126));
        userImageButton.setName("userImageButton"); // NOI18N
        userImageButton.setOpaque(false);
        userImageButton.setPreferredSize(new java.awt.Dimension(109, 126));
        userImageButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                userImageButtonActionPerformed(evt);
            }
        });

        questionButton5.setFont(resourceMap.getFont("questionButton5.font")); // NOI18N
        questionButton5.setText(resourceMap.getString("questionButton5.text")); // NOI18N
        questionButton5.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton5.setName("questionButton5"); // NOI18N
        questionButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton5ActionPerformed(evt);
            }
        });

        questionButton6.setFont(resourceMap.getFont("questionButton6.font")); // NOI18N
        questionButton6.setText(resourceMap.getString("questionButton6.text")); // NOI18N
        questionButton6.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton6.setName("questionButton6"); // NOI18N
        questionButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton6ActionPerformed(evt);
            }
        });

        questionButton7.setFont(resourceMap.getFont("questionButton7.font")); // NOI18N
        questionButton7.setText(resourceMap.getString("questionButton7.text")); // NOI18N
        questionButton7.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton7.setName("questionButton7"); // NOI18N
        questionButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton7ActionPerformed(evt);
            }
        });

        questionButton3.setFont(resourceMap.getFont("questionButton3.font")); // NOI18N
        questionButton3.setText(resourceMap.getString("questionButton3.text")); // NOI18N
        questionButton3.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton3.setName("questionButton3"); // NOI18N
        questionButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton3ActionPerformed(evt);
            }
        });

        questionButton4.setFont(resourceMap.getFont("questionButton4.font")); // NOI18N
        questionButton4.setText(resourceMap.getString("questionButton4.text")); // NOI18N
        questionButton4.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton4.setName("questionButton4"); // NOI18N
        questionButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton4ActionPerformed(evt);
            }
        });

        questionButton8.setFont(resourceMap.getFont("questionButton8.font")); // NOI18N
        questionButton8.setText(resourceMap.getString("questionButton8.text")); // NOI18N
        questionButton8.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton8.setName("questionButton8"); // NOI18N
        questionButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton8ActionPerformed(evt);
            }
        });

        questionButton9.setFont(resourceMap.getFont("questionButton9.font")); // NOI18N
        questionButton9.setText(resourceMap.getString("questionButton9.text")); // NOI18N
        questionButton9.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton9.setName("questionButton9"); // NOI18N
        questionButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton9ActionPerformed(evt);
            }
        });

        questionButton11.setFont(resourceMap.getFont("questionButton11.font")); // NOI18N
        questionButton11.setText(resourceMap.getString("questionButton11.text")); // NOI18N
        questionButton11.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton11.setName("questionButton11"); // NOI18N
        questionButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton11ActionPerformed(evt);
            }
        });

        questionButton2.setFont(resourceMap.getFont("questionButton2.font")); // NOI18N
        questionButton2.setText(resourceMap.getString("questionButton2.text")); // NOI18N
        questionButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton2.setName("questionButton2"); // NOI18N
        questionButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton2ActionPerformed(evt);
            }
        });

        questionButton10.setFont(resourceMap.getFont("questionButton10.font")); // NOI18N
        questionButton10.setText(resourceMap.getString("questionButton10.text")); // NOI18N
        questionButton10.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton10.setName("questionButton10"); // NOI18N
        questionButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton10ActionPerformed(evt);
            }
        });

        questionButton14.setFont(resourceMap.getFont("questionButton14.font")); // NOI18N
        questionButton14.setText(resourceMap.getString("questionButton14.text")); // NOI18N
        questionButton14.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton14.setName("questionButton14"); // NOI18N
        questionButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton14ActionPerformed(evt);
            }
        });

        questionButton13.setFont(resourceMap.getFont("questionButton13.font")); // NOI18N
        questionButton13.setText(resourceMap.getString("questionButton13.text")); // NOI18N
        questionButton13.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton13.setName("questionButton13"); // NOI18N
        questionButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton13ActionPerformed(evt);
            }
        });

        questionButton12.setFont(resourceMap.getFont("questionButton12.font")); // NOI18N
        questionButton12.setText(resourceMap.getString("questionButton12.text")); // NOI18N
        questionButton12.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton12.setName("questionButton12"); // NOI18N
        questionButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton12ActionPerformed(evt);
            }
        });

        questionButton15.setFont(resourceMap.getFont("questionButton15.font")); // NOI18N
        questionButton15.setText(resourceMap.getString("questionButton15.text")); // NOI18N
        questionButton15.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton15.setName("questionButton15"); // NOI18N
        questionButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton15ActionPerformed(evt);
            }
        });

        questionButton20.setFont(resourceMap.getFont("questionButton20.font")); // NOI18N
        questionButton20.setText(resourceMap.getString("questionButton20.text")); // NOI18N
        questionButton20.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton20.setName("questionButton20"); // NOI18N
        questionButton20.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton20ActionPerformed(evt);
            }
        });

        questionButton19.setFont(resourceMap.getFont("questionButton19.font")); // NOI18N
        questionButton19.setText(resourceMap.getString("questionButton19.text")); // NOI18N
        questionButton19.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton19.setName("questionButton19"); // NOI18N
        questionButton19.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton19ActionPerformed(evt);
            }
        });

        questionButton18.setFont(resourceMap.getFont("questionButton18.font")); // NOI18N
        questionButton18.setText(resourceMap.getString("questionButton18.text")); // NOI18N
        questionButton18.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton18.setName("questionButton18"); // NOI18N
        questionButton18.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton18ActionPerformed(evt);
            }
        });

        questionButton17.setFont(resourceMap.getFont("questionButton17.font")); // NOI18N
        questionButton17.setText(resourceMap.getString("questionButton17.text")); // NOI18N
        questionButton17.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton17.setName("questionButton17"); // NOI18N
        questionButton17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton17ActionPerformed(evt);
            }
        });

        questionButton16.setFont(resourceMap.getFont("questionButton16.font")); // NOI18N
        questionButton16.setText(resourceMap.getString("questionButton16.text")); // NOI18N
        questionButton16.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton16.setName("questionButton16"); // NOI18N
        questionButton16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton16ActionPerformed(evt);
            }
        });

        questionButton1.setFont(resourceMap.getFont("questionButton1.font")); // NOI18N
        questionButton1.setText(resourceMap.getString("questionButton1.text")); // NOI18N
        questionButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
        questionButton1.setName("questionButton1"); // NOI18N
        questionButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                questionButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(43, 43, 43)
                        .addComponent(previousButton, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(questionButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(questionButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(questionButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(questionButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(questionButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(questionButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(questionButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(questionButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(questionButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2)
                        .addComponent(questionButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(pluggisRuggis, javax.swing.GroupLayout.PREFERRED_SIZE, 309, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(answerField, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(questionNumber)
                            .addComponent(questionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(questionButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(2, 2, 2)
                                .addComponent(questionButton12, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(2, 2, 2)
                                .addComponent(questionButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(2, 2, 2)
                                .addComponent(questionButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(2, 2, 2)
                                .addComponent(questionButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(2, 2, 2)
                                .addComponent(questionButton16, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(2, 2, 2)
                                .addComponent(questionButton17, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(2, 2, 2)
                                .addComponent(questionButton18, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(2, 2, 2)
                                .addComponent(questionButton19, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(2, 2, 2)
                                .addComponent(questionButton20, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(nextButton)))
                        .addContainerGap(66, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(userImageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(78, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(questionNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(questionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(answerField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(pluggisRuggis, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(76, 76, 76))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(userImageButton, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(questionButton12, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton13, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton14, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton7, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton6, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton8, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton9, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton10, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton11, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton15, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton16, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton17, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton18, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton19, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(questionButton20, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE)
                    .addComponent(nextButton, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(previousButton, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(questionButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE))
                .addGap(45, 45, 45))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void previousButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_previousButtonActionPerformed
        storeAnswer();
        Test.getInstance().lastQuestion();
}//GEN-LAST:event_previousButtonActionPerformed

    private void nextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextButtonActionPerformed
        storeAnswer();
        Test.getInstance().nextQuestion();
}//GEN-LAST:event_nextButtonActionPerformed

    private void userImageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_userImageButtonActionPerformed
        int messageType = JOptionPane.QUESTION_MESSAGE;
        String[] options = {"Ja", "Nej"};
        int code = JOptionPane.showOptionDialog(null,
                "Vill du avbryta testet och gå till ditt ugglebo?",
                "", 0, messageType,
                null, options, "Nej");
        if (code == 0) {
            Pluggis g = Pluggis.getInstance();
            g.getMainView().removeAll();
            g.getMainView().add(new LoggedInView());
            g.getMainView().repaint();
            g.getMainView().validate();
        }
    }//GEN-LAST:event_userImageButtonActionPerformed

    void setNextButton(int i) {
        if (i == 0) {
            nextButton.setText("Framåt>>");
        } else {
            nextButton.setText("Rätta>>  ");
        }
    }

    void setQuestion(int i) {
        storeAnswer();
        Test.getInstance().setQuestion(i);
    }

    private void storeAnswer() {
        try {
            svar = Integer.parseInt(answerField.getText());
            Test.getInstance().getCurrentQuestion().saveUserAnswer(svar);
        } catch (NumberFormatException nfe) {
            Test.getInstance().getCurrentQuestion().notAnswered();
        }
    }

    void setButtonColor(int i) {
        int pos = i;
        JButton[] buttonList = {questionButton1, questionButton2, questionButton3, questionButton4, questionButton5, questionButton6, questionButton7, questionButton8, questionButton9, questionButton10, questionButton11, questionButton12, questionButton13, questionButton14, questionButton15, questionButton16, questionButton17, questionButton18, questionButton19, questionButton20};
        buttonList[pos].setBackground(Color.red);
    }

    private void questionButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton2ActionPerformed
        setQuestion(2);
    }//GEN-LAST:event_questionButton2ActionPerformed

    private void questionButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton3ActionPerformed
        setQuestion(3);
    }//GEN-LAST:event_questionButton3ActionPerformed

    private void questionButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton4ActionPerformed
        setQuestion(4);
    }//GEN-LAST:event_questionButton4ActionPerformed

    private void questionButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton5ActionPerformed
        setQuestion(5);
    }//GEN-LAST:event_questionButton5ActionPerformed

    private void questionButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton6ActionPerformed
        setQuestion(6);
    }//GEN-LAST:event_questionButton6ActionPerformed

    private void questionButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton7ActionPerformed
        setQuestion(7);
    }//GEN-LAST:event_questionButton7ActionPerformed

    private void questionButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton8ActionPerformed
        setQuestion(8);
    }//GEN-LAST:event_questionButton8ActionPerformed

    private void questionButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton9ActionPerformed
        setQuestion(9);
    }//GEN-LAST:event_questionButton9ActionPerformed

    private void questionButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton10ActionPerformed
        setQuestion(10);
    }//GEN-LAST:event_questionButton10ActionPerformed

    private void questionButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton11ActionPerformed
        setQuestion(11);
    }//GEN-LAST:event_questionButton11ActionPerformed

    private void questionButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton12ActionPerformed
        setQuestion(12);
    }//GEN-LAST:event_questionButton12ActionPerformed

    private void questionButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton13ActionPerformed
        setQuestion(13);
    }//GEN-LAST:event_questionButton13ActionPerformed

    private void questionButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton14ActionPerformed
        setQuestion(14);
    }//GEN-LAST:event_questionButton14ActionPerformed

    private void questionButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton15ActionPerformed
        setQuestion(15);
    }//GEN-LAST:event_questionButton15ActionPerformed

    private void questionButton16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton16ActionPerformed
        setQuestion(16);
    }//GEN-LAST:event_questionButton16ActionPerformed

    private void questionButton17ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton17ActionPerformed
        setQuestion(17);
    }//GEN-LAST:event_questionButton17ActionPerformed

    private void questionButton18ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton18ActionPerformed
        setQuestion(18);
    }//GEN-LAST:event_questionButton18ActionPerformed

    private void questionButton19ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton19ActionPerformed
        setQuestion(19);
    }//GEN-LAST:event_questionButton19ActionPerformed

    private void questionButton20ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton20ActionPerformed
        setQuestion(20);
    }//GEN-LAST:event_questionButton20ActionPerformed

    private void questionButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_questionButton1ActionPerformed
        setQuestion(1);
    }//GEN-LAST:event_questionButton1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField answerField;
    private javax.swing.JButton nextButton;
    private javax.swing.JLabel pluggisRuggis;
    private javax.swing.JButton previousButton;
    private javax.swing.JButton questionButton1;
    private javax.swing.JButton questionButton10;
    private javax.swing.JButton questionButton11;
    private javax.swing.JButton questionButton12;
    private javax.swing.JButton questionButton13;
    private javax.swing.JButton questionButton14;
    private javax.swing.JButton questionButton15;
    private javax.swing.JButton questionButton16;
    private javax.swing.JButton questionButton17;
    private javax.swing.JButton questionButton18;
    private javax.swing.JButton questionButton19;
    private javax.swing.JButton questionButton2;
    private javax.swing.JButton questionButton20;
    private javax.swing.JButton questionButton3;
    private javax.swing.JButton questionButton4;
    private javax.swing.JButton questionButton5;
    private javax.swing.JButton questionButton6;
    private javax.swing.JButton questionButton7;
    private javax.swing.JButton questionButton8;
    private javax.swing.JButton questionButton9;
    public javax.swing.JLabel questionLabel;
    public javax.swing.JLabel questionNumber;
    private javax.swing.JButton userImageButton;
    // End of variables declaration//GEN-END:variables

    void setVariables(Test t) {
        questionNumber.setText("Fråga: " + t.getCurrentQuestion().getQuestionNumber());
        questionLabel.setText("Vad är " + t.getCurrentQuestion().getQuestion() + "?");
        if (t.getCurrentQuestion().isAnswered()) {
            answerField.setText("" + t.getCurrentQuestion().getUserAnswer());
        } else {
            answerField.setText("");
        }
        answerField.requestFocusInWindow();
        userImageButton.setIcon(Pluggis.getInstance().getSelectedUser().getImage());
        answerField.requestFocusInWindow();
    }
}
